//
// Created by Suzhen on 2017/2/27.
//

#ifndef ORIONV2_SOCKETACCEPTOR_H
#define ORIONV2_SOCKETACCEPTOR_H

#include "FileStream.h"
#include "IOBehavior.h"

ORION_V2_NAMESPACE_BEGIN

        //todo 需要支持拒绝连接的功能，当服务器关闭的时候，可以手动关闭acceptor的功能,以确保generator能被正常关闭
        class SocketAcceptor : public FileStream {

        public:
            virtual ~SocketAcceptor();

            /**
             * 继承FileStream
             * idleTime 设置为0,表示永不超时
             * @param cnf
             */
            SocketAcceptor(Configuration &&,
                           const IOBehavior &userDefinedIob,
                           TlsConf &&tls = TlsConf());
            
            void setCustomAcceptorIOBehavior(const IOBehavior & iob);

        protected:
            void onStreamIO(int status, EventFlag ioe) override;

        public:
            void attach(AsyncEventGenerator *gen) override;

        private:
            Configuration configurations_;
            IOBehavior userIob_;
            TlsConf tlsConf_;
        };

ORION_V2_NAMESPACE_END

#endif //ORIONV2_SOCKETACCEPTOR_H
